package leetcode.editor.cn;

public class P343IntegerBreak {
    public static void main(String[] args) {
        Solution solution = new P343IntegerBreak().new Solution();
        System.out.println(solution.integerBreak(10));

    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        int maxValue = Integer.MIN_VALUE;

        public int integerBreak(int n) {
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                int curMax = 0;
                for (int j = 1; j <= i; j++) {
                    curMax = Math.max(curMax, Math.max(j * (i - j), arr[i - j] * j));
                }
                arr[i] = curMax;
            }
            return arr[n];
        }

        public int integerBreak2(int n) {
            if (n == 2) {
                return 1;
            }
            if (n == 3) {
                return 2;
            }
            int sum = 1;
            while (n != 0) {
                n -= 3;
                if (n == 1) {
                    sum *= 4;
                    break;
                }
                sum *= 3;
                if (n == 2) {
                    sum *= 2;
                    break;
                }
            }
            return sum;
        }

        public int integerBreak1(int n) {
            integerComp(n, 1, 0);
            return maxValue;
        }

        public void integerComp(int n, int mul, int dep) {
            if (dep > 1) {
                if (n == 1 || n == 0) {
                    maxValue = Math.max(mul, maxValue);
                }
            }
            for (int i = 1; i <= n; i++) {
                integerComp(n - i, mul * i, dep + 1);
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}